import java.awt.Color;
import java.awt.Font;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.Random;

import ij.IJ;
import ij.ImagePlus;
import ij.gui.NewImage;
import ij.plugin.PlugIn;
import ij.process.ImageProcessor;
// Moyenne de n images

public class station3 extends ImagePlus implements PlugIn{
	
	//private ImageProcessor primeIP; 
	private int X=1024,Y=768; // image size
	
	private ImagePlus maskAlpha;  
	private ImageProcessor maskAlphaIP;  

	
	private Random generator=new Random(12104); 
	
	public void run(String arg) {
		System.out.println("go");
		
		
 			ImagePlus laListe[]=new ImagePlus[65];
 			ImageProcessor lesProcs[]=new ImageProcessor[65]; 
 			
 			 File dir = new File("E:/gare");
 		    File[] list = dir.listFiles();
 		    for (int i=0;i<64;i++) {
 		    	System.out.println(i); 
 		    	laListe[i]=IJ.openImage(list[i].toString()) ;
 		    	lesProcs[i]=laListe[i].getProcessor();
 		    }
 		  
	ImagePlus image1=NewImage.createRGBImage ("Image1",X,Y, 1, NewImage.FILL_WHITE);
	ImageProcessor i1=image1.getProcessor();
	
				for(int i=0;i<X;i++){
						for(int j=0;j<Y;j++){
							int A=0,B=0,C=0;
							//System.out.println("****"); 
							for(int k=0;k<64;k++){
							int val=lesProcs[k].getPixel(i,j); 
							//System.out.println(Integer.toHexString(val));
							A=(A+((val & 0x00FF0000) >>16));
							B=(B+((val & 0x0000FF00) >>8));
							C=C+(val & 0x000000FF);
							//System.out.println(A+" "+B+" "+C);
							
							}
							A=(A/64)%256; 
							B=(B/64)%256; 
							C=(C/64)%256;
							System.out.println(A+" "+B+" "+C);
							System.out.println((0xFF000000 |((A<<16)+(B<<8)+C))+" "+Integer.toHexString(0xFF000000 |((A<<16)+(B<<8)+C)));
							i1.putPixel(i,j,0xFF000000 |((A<<16)+(B<<8)+C));
			
		}// y
     }//x
	image1.show();
}
	

}